<template>
  <el-dialog
      v-model="showFlag"
      title="配置信息"
      width="70%"
      :before-close="handleConfigClose"
  >
    <el-form :model="form" label-width="80">
      <el-row>
        <el-col :span="12">
          <el-form-item label="作者" prop="author">
            <el-input v-model="form.author" placeholder="作者"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="父类" prop="superClass">
            <el-input v-model="form.superClass" placeholder="父类"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="表前缀" prop="tablePrefix">
            <el-input v-model="form.tablePrefix" placeholder="表前缀"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="字段前缀" prop="fieldPrefix">
            <el-input v-model="form.fieldPrefix" placeholder="字段前缀"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="基础包名" prop="basePackage">
            <el-input v-model="form.basePackage" placeholder="基础包名"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="时间类型" prop="dateType">
            <el-select
                v-model="form.dateType"
                placeholder="请选择时间类型"
                filterable
            >
              <el-option
                  v-for="(item, index) in dateTypeOptions"
                  :key="index"
                  :label="item"
                  :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="Lombok" prop="lombok">
            <el-select
                v-model="form.lombok"
                filterable
            >
              <el-option
                  v-for="(item, index) in switchOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="Swagger" prop="swagger">
            <el-select
                v-model="form.swagger"
                filterable
            >
              <el-option
                  v-for="(item, index) in swaggerOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="分页插件" prop="page">
            <el-select
                v-model="form.page"
                filterable
            >
              <el-option
                  v-for="(item, index) in pager"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="导入导出" prop="export">
            <el-select
                v-model="form.exportFlag"
                filterable
            >
              <el-option
                  v-for="(item, index) in switchOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <el-button @click="saveConfig" type="primary">保存</el-button>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>
import {strIsBlank} from "../../utils/util.js";

export default {
  name: 'ConfigDialog',
  props: {
    configVisible: Boolean,
    config: Object
  },
  watch: {
    configVisible(newVal) {
      this.showFlag = newVal
    },
    config(newVal) {
      this.form = this.config
    }
  },
  beforeMount() {
    const item = localStorage.getItem('config');
    if (!strIsBlank(item)){
      this.form = JSON.parse(item)
    }
  },
  data() {
    return {
      showFlag: this.configVisible,
      form: {
        author: 'eleven',
        superClass: 'net.lesscoding.common.BaseEntity',
        tablePrefix: 'tb_',
        fieldPrefix: '',
        basePackage: 'net.lesscoding',
        dateType: 'LocalDateTime',
        lombok: true,
        swagger: 'knife4j',
        page: 'mybatisPage',
        exportFlag: false
      },
      dateTypeOptions: [
        "LocalDateTime",
        "LocalDate",
        "Date",
        "Timestamp"
      ],
      switchOptions: [
        {
          label: '启用',
          value: true
        },
        {
          label: '禁用',
          value: false
        }
      ],
      swaggerOptions: [
        {
          label: "禁用",
          value: "disabled"
        },
        {
          label: "Swagger",
          value: "swagger"
        },{
          label: "Knife4j",
          value: "knife4j"
        }
      ],
      pager: [
        {
          label: "PageHelper",
          value: "pageHelper"
        },
        {
          label: "MybatisPage",
          value: "mybatisPage"
        }
      ]
    }
  },
  methods: {
    handleConfigClose() {
      this.$emit('handle-dialog-close', 'config')
    },
    saveConfig() {
      this.$emit('save-config', this.form)

    }
  }
}
</script>
<style></style>
